# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=ruby-set
_pkgname="${pkgname#ruby-}"
pkgver=1.0.3
pkgrel=2
pkgdesc='This library provides the Set class'
arch=('any')
url='https://github.com/ruby/set'
license=('BSD')
depends=('ruby')
makedepends=('git')
checkdepends=('ruby-rake' 'ruby-minitest' 'ruby-test-unit')
options=('!emptydirs')
_commit='e2419f2d30559e12f823b482726f8b1a47a8bc30'
source=("$pkgname::git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # we do not do version pinning
  sed --regexp-extended 's/~>/>=/g' --in-place *.gemspec Gemfile Rakefile
}

build() {
  cd "$pkgname"

  gem build "$_pkgname.gemspec"
}

check() {
  cd "$pkgname"

  rake test
}

package() {
  cd "$pkgname"

  local _gemdir="$(gem env gemdir)"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "$pkgdir/$_gemdir" \
    --bindir "$pkgdir/usr/bin" \
    "$_pkgname-$pkgver.gem"

  # delete cache
  rm -rf "$pkgdir/$_gemdir/cache"

  # license
  install -vd "$pkgdir/usr/share/licenses/$pkgname"
  ln -sf "$_gemdir/gems/$_pkgname-$pkgver/LICENSE.txt" "$pkgdir/usr/share/licenses/$pkgname"
}
